//
//  UATLoadingViewController.m
//  UStarter_Example
//
//  Created by Mark on 2021/1/7.
//  Copyright © 2021 mark5566. All rights reserved.
//

#import "UATLoadingViewController.h"
#import "UATViewController.h"
#import <UATStarter.h>

@interface UATLoadingViewController ()<UIPopoverPresentationControllerDelegate>

{
    UIButton * btn ;
}

@end

@implementation UATLoadingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setup];
}

- (void) setup {
    btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame =CGRectMake(100, 100, 100, 50);
    NSString * title = self.title==nil?@"默认标题":self.title;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(toNavigate:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
//    self.title = @"loading";
    int i = [self.title intValue];

    
    
    
}

- (void) toNavigate:(UIButton*)sender {
//    NSString * homePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
//    NSURL * url = [[NSFileManager defaultManager] URLForDirectory:NSDocumentationDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:nil error:nil];
//    url = [url URLByAppendingPathComponent:@"default/hello.jpg"];
//    DLog(@"path:%@",url.absoluteString);
//    NSError * err ;
//    NSString * path = [homePath stringByAppendingPathComponent:@"01.jpg"];
//    url = [NSURL fileURLWithPath:path];
//    if([[NSFileManager defaultManager] fileExistsAtPath:url.absoluteString ]){
//        DLog(@"exist file ");
//    }
//    NSData * data = [NSData dataWithContentsOfURL:url  options:NSDataReadingMappedIfSafe error:&err];
//
//    [UATApi uploadAction:@"http://ssl.zhuanyegou.com/fileServer/file/upload" withParam:@{@"project":@"test",@"showName":@"false"} data:@{} fileData:data fileKey:@"pic" cb:^(UATApiRequstStatus status, id  _Nullable responseObjec, NSProgress * _Nullable progress, NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
//        if(status == UATApiRequestStatusDOING){
//            DLog(@"uploading...%lld",progress.completedUnitCount);
//        }
//        if(status == UATApiRequestStatusSUCCESS){
//            DLog(@"res:%@",responseObjec);
//        }
//        if(status == UATApiRequestStatusFAIL){
//            DLog(@"err:%@",error);
//        }
//
//    }];
    
    UATLoadingViewController * l = [UATLoadingViewController new];
    int i = arc4random() % 100 ;
    l.title=[NSString stringWithFormat:@"%d",i];
    
    [[UATStarter shareRoute] pushViewController:l animated:true];
    
}
- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController;{
    DLog(@"prepare show ..");
}


@end
